package com.swt.controller.T_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Club;
import com.swt.domain.Staff;
import com.swt.service.T_service.StaffService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class StaffController {
    @Resource(name = "TTStaffServiceImp")
    private StaffService staffService;


    @RequestMapping("/staffAdd")
    @ResponseBody
    public String staffAdd(String staffname,String staffphone,String staffsex,String staffrole,String staffsupport,String staffimg,int shopid,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();

        Boolean  staffAddBoolean  =  staffService.staffAdd(staffname,staffphone,staffsex,staffrole,staffsupport,staffimg,shopid,clubClubId);

      return JSON.toJSONString(staffAddBoolean);
    }
    @RequestMapping("/staffQuery")
    @ResponseBody
    public String  staffQuery(int page,String query,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        System.out.println(query+"==============");
       List<Staff> staffList = staffService.staffQuery(page,query,clubClubId);
       return  JSON.toJSONString(staffList);
    }
//    员工删除方法通过id
    @RequestMapping("/staffDelete")
    @ResponseBody
    public String staffDalete(int staffid){
       Boolean staffDelete  = staffService.staffDelete(staffid);

        return JSON.toJSONString(staffDelete);
    }

    @RequestMapping("/staffQuery2")
    @ResponseBody
    public String staffQuert2(int staffid){
         List<Staff> staffList = staffService.staffQuery2(staffid);
         return JSON.toJSONString(staffList);
    }
//排课界面查询教练人员
    @RequestMapping("/queryStaffPK")
    @ResponseBody
    public String queryStaffPK(HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        List<Staff> staffList = staffService.queryStaffPK(clubClubId);
        return JSON.toJSONString(staffList);
    }


    @RequestMapping("/staffUpdate")
    @ResponseBody
    public String staffUpdate(int staffid, String staffname,String staffphone,String staffsex,String staffrole,String staffsupport,String staffimg,int shopid){
        Boolean  staffAddBoolean  =  staffService.staffUpdate(staffid,staffname,staffphone,staffsex,staffrole,staffsupport,staffimg,shopid);
        return JSON.toJSONString(staffAddBoolean);
    }


    public StaffService getStaffService() {
        return staffService;
    }

    public void setStaffService(StaffService staffService) {
        this.staffService = staffService;
    }
}
